<!--  -->
<template>
  <div>
    <div class="pending">
    <el-tabs v-model="form.checkedStatus" @tab-click="handleClick">
        <el-tab-pane label="全部" name="null" />
        <el-tab-pane label="未提交" name="0" />
        <el-tab-pane label="审批中" name="1" />
        <el-tab-pane label="已上架" name="2" />
        <el-tab-pane label="审批不通过" name="3" />
        <el-tab-pane label="已下架" name="4" />
      </el-tabs>
      <!-- 搜索 -->
      <div class="formSearch">
        <el-form :inline="true" :model="form" class="demo-form-inline">
          <el-form-item label="库存状态">
            <el-select v-model="form.stock" placeholder="请选择上架状态">
              <el-option label="全部" :value="null" />
              <el-option label="有库存" value="1" />
              <el-option label="无库存" value="0" />
            </el-select>
          </el-form-item>

          <el-form-item>
            <el-button type="primary" plain @click="search">查询</el-button>
            <el-button plain @click="clear">重置</el-button>
            <!-- <el-button plain @click="skuadd">新增</el-button> -->
            <!-- <span v-for="(item,index) in btnList" :key="index" class="promissStyle">
              <el-button type="success" plain @click="btnClick(item)">{{ item.permissionName }}</el-button>
            </span> -->
            <!-- <el-button type="success" plain @click="add()">新增商品</el-button> -->
          </el-form-item>
        </el-form>
      </div>
      <!-- 表格 -->
      <div class="tableBox">
        <el-table
          ref="multipleTable"
          :data="tableData"
          border
          :header-cell-style="{ background: '#EEF3FF', color: '#333333' }"
          tooltip-effect="dark"
          style="width: 100%"
        >
        <el-table-column label="商家名称">
          <template slot-scope="scope">{{ scope.row.shopName }}</template>
        </el-table-column>

         <!-- <el-table-column label="商品名称">
          <template slot-scope="scope">{{ scope.row.title }}</template>
        </el-table-column> -->

         <el-table-column label="审批状态">
            <template slot-scope="scope">
              <span v-if="scope.row.checkedStatus==0">未申请</span>
              <span v-if="scope.row.checkedStatus==1">审批中</span>
              <span v-if="scope.row.checkedStatus==2">审批通过</span>
              <span v-if="scope.row.checkedStatus==3">审批不通过</span>
            </template>
          </el-table-column>

        <el-table-column label="平台分类">
            <template slot-scope="scope">{{ scope.row.classifyName }}</template>
          </el-table-column>
        
        <!-- <el-table-column label="店铺分类">
            <template slot-scope="scope">{{ scope.row.shopClassifyName }}</template>
          </el-table-column> -->

        <el-table-column label="原价" >
            <template slot-scope="scope">{{ scope.row.originalPrice }}</template>
          </el-table-column>

        <el-table-column label="售价">
            <template slot-scope="scope">{{ scope.row.price }}</template>
          </el-table-column>

        <el-table-column label="SKU短标题">
            <template slot-scope="scope">{{ scope.row.sku }}</template>
          </el-table-column>

        <el-table-column label="商品封面">
          <template slot-scope="scope">
            <img :src="scope.row.pic" @click="previewPic(scope.row.pic)" style="width:60px;height:60px;" />
          </template>
        </el-table-column>

        <el-table-column label="库存数量">
            <template slot-scope="scope">{{ scope.row.stockNumber }}</template>
          </el-table-column>
        <!-- <el-table-column label="库存总数">
            <template slot-scope="scope">{{ scope.row.total }}</template>
          </el-table-column> -->
        <el-table-column label="销量">
            <template slot-scope="scope">{{ scope.row.saleNumber }}</template>
          </el-table-column>

          <el-table-column label="上架时间" >
            <template slot-scope="scope">{{ scope.row.saleTime }}</template>
          </el-table-column>

          <el-table-column label="自定义标题列" >
            <template slot-scope="scope">{{ scope.row.skuTitle }}</template>
          </el-table-column>

          <el-table-column label="操作" width="200">
            <template slot-scope="scope">
              <div class="btnList">
                <el-button type="text" @click="apply(scope.row)">审核</el-button>
                <el-button type="text" @click="detail(scope.row)">查看详情</el-button>
                <!-- <el-button type="text" @click="edit(scope.row)">编辑</el-button> -->
                <el-button type="text" @click="offShelf(scope.row)">下架</el-button>
                <!-- <el-button type="text" @click="del(scope.row)">删除</el-button> -->
              </div>
            </template>
          </el-table-column>
        </el-table>
        <div class="fenye">
          <el-pagination
            :current-page="currentPage"
            :page-sizes="[10, 20, 50, 100]"
            :page-size="10"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
          />
        </div>
      </div>
    </div>

    <detail
      ref="detail"
      v-if="detailDialog"
      :skuId="skuId"
    />

    <!-- 图片预览 -->
    <el-dialog :visible.sync="dialogVisible" :close-on-click-modal="false" title="图片预览" width="50%">
      <img :src="previewpic" alt="" width="100%" />         
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>

    <el-dialog title="审核" :visible.sync="dialogFormVisible" width="600px">
      <el-form :model="form">
        <el-form-item label="SKU短标题" :label-width="formLabelWidth">
          <el-input
            disabled
            placeholder="请输入内容"
            v-model="form1.sku">
          </el-input>
        </el-form-item>
        <el-form-item label="审批状态" :label-width="formLabelWidth">
          <el-select v-model="form1.checkedStatus" placeholder="请选择">
              <el-option
                v-for="item in checkedStatusList1"
                :key="item.id"
                :label="item.value"
                :value="item.id"
              >
              </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="审批备注" v-if="form1.checkedStatus==3" :label-width="formLabelWidth">
          <el-input
            type="textarea"
            :rows="2"
            placeholder="请输入内容"
            v-model="form1.checkedRemark">
          </el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="audit">确 定</el-button>
      </div>
    </el-dialog>

    <!-- <pic-upload v-model="dataGroup.image.src" style="width: 500px;" /> -->
  </div>
</template>

<script>
// 这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
// 例如：import 《组件名称》 from '《组件路径》';
import { getBtnList } from '@/utils/auth'
import { skuGetAll,delskuId,offShelf,skuApply } from '@/api/sku'
import { detail } from './detail'
// import GropeEdit from './Edit'
export default {
  components: {
    // GropeEdit
    detail
  },
  data() {
    // 这里存放数据
    return {
          checkedStatusList1:[
            {
                id:2,
                value:'审批通过'
            },
            {
                id:3,
                value:'审批不通过'
            }
        ],
      dialogFormVisible: false,
      form1: {
        checkedStatus: 2,
        checkedRemark: '',
        skuId: 0
      },
      formLabelWidth: '100px',
      dialogVisible:false,
      previewpic: "",
      skuId:0,
      detailDialog:false,//查看详情
      stockList:[
          {
              id:null,
              value:'全部'
          },
          {
              id:0,
              value:'无'
          },
          {
              id:1,
              value:'有'
          }
      ],
      shelveStateList:[
          {
              id:null,
              value:'全部'
          },
          {
              id:0,
              value:'否'
          },
          {
              id:1,
              value:'是'
          }
      ],
      checkedStatusList:[
          {
              id:null,
              value:'全部'
          },
          {
              id:0,
              value:'未提交'
          },
          {
              id:1,
              value:'审批中'
          },
          {
              id:2,
              value:'已上架'
          },
          {
              id:3,
              value:'审批不通过'
          },
            {
              id:4,
              value:'已下架'
          },
      ],
      form:{
          checkedStatus: 'null',
          page: 1,
          pageSize: 10,
          productId: 0,
          stock: null
      },
      btnList: '',
      formParams: {
        logisticsName: '',
        page: 1,
        pageSize: 10
      },
      total: 1,
      tableData: [],
      currentPage: 1,
      dialog: {
        type: 'add',
        isVisible: false
      }
    }
  },
  // 监听属性 类似于data概念
  computed: {},
  // 监控data中的数据变化
  watch: {},
  // 生命周期 - 创建完成（可以访问当前this实例）
  created() {},
  // 生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {
    if(this.$route.query.productId) {
      this.productId = this.$route.query.productId
    }
    this.init(this.form)
  },
  // 方法集合
  methods: {
    //预览大图
    previewPic(url) {
      this.previewpic = url;
      this.dialogVisible = true;
    },
    handleClick(tab, event) {
      console.log(tab)
      this.form.state = tab.name
      this.init(this.form)
    },
    skuadd() {
      this.$router.push('skuadd')
    },
    audit() {
      skuApply(this.form1).then(res=>{
        if(res.data) {
          this.$message({
            type: 'success',
            message: '提交审核成功!'
          })
          this.dialogFormVisible = false;
          this.init(this.form)
        }
      })
    },
    apply(row) {
      this.dialogFormVisible = true;
      this.form1.skuId = row.skuId;
      this.form1.sku = row.sku;
    },
    offShelf(row){
      offShelf(row.skuId).then(res=>{
        if(res.data) {
          this.$message({
            type: 'success',
            message: '下架成功!'
          })
          this.init(this.form)
        }
      })
    },
    input(e) {
      this.form.productId =e;
    },
    clear() {
      this.form = {
        checkedStatus: null,
        page: 0,
        pageSize: 0,
        productId: 0,
        shelveState: null,
        stock: null
      }
    },
    search() {
      skuGetAll(this.form).then(res=>{
          this.tableData = res.data.content;
          this.total = res.data.totalElements
      })
    },
    del(row) {
      delskuId({skuId:row.skuId}).then(res=>{
        this.tableData = res.data.content;
        this.total = res.data.totalElements
      })
    },
    init(data){
      skuGetAll(data).then(res=>{
        console.log(res,"测试查看111111111")
        this.tableData = res.data.content;
        this.total = res.data.totalElements
      })
    },
    btnClick(id) {
      console.log(id)
      if (id.permissionName === '新建方案') {
        this.add()
      }
    },
    handleSizeChange(val) {
      this.form.pageSize = val
      this.init(this.form)
    },
    handleCurrentChange(val) {
      this.form.page = val
      this.init(this.form)
    },

    add() {
      this.dialog = {
        type: 'add',
        isVisible: true
      }
    },
    // 查看
    detail(row) {
      localStorage.setItem('skuId',row.skuId);
      this.$router.push('skudetail');
    },
    // 编辑
    edit(row) {
      localStorage.setItem('skuId',row.skuId);
      this.$router.push('skuedit');
    },
    // 关闭弹框
    editClose() {
      this.dialog.isVisible = false
    },
    // 删除
    del(row) {
      this.$confirm('选中数据将被永久删除, 是否继续？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          delskuId({skuId:row.skuId}).then(res=>{
            if(res.data) {
              this.$message({
                type: 'success',
                message: '删除成功!'
              })
              this.init(this.form)
            }
          })
        })
        .catch(() => {})
    },
  }
}
</script>
<style lang='scss' scoped>
//@import url(); 引入公共css类
@import url("../../styles/elDialog.scss");
.pending {
  padding: 30px;
}
.fenye {
  margin-top: 20px;
}
</style>
